//
//  RMMGoodsDetailsHeadView.m
//  Romomo
//
//  Created by puman on 16/10/11.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMGoodsDetailsHeadView.h"
@implementation RMMGoodsDetailsHeadView
{
    UIImageView *_imageV;
    UILabel *_titleLabel;
    UILabel *_prcieLabel;
    UILabel *_deleteLabel;
    UILabel *_timeLabel;
    UILabel *_lineLabel;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWideth,kScreenWideth)];
        [self addSubview:_imageV];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, _imageV.bottom + 12, _imageV.width - 30, kHalf)];
        _titleLabel.textColor = COLORFROMCODE(0x303137, 1);
        _titleLabel.font = kFont(14);
        _titleLabel.numberOfLines = 0;
        [self addSubview:_titleLabel];
        
        _prcieLabel = [[UILabel alloc] initWithFrame:CGRectMake(_titleLabel.left, _titleLabel.bottom + 6, 2 * kHalf, kMaric)];
        _prcieLabel.textColor = COLORFROMCODE(0x4A4A4A, 1);
        _prcieLabel.font = kFont(24);
        [self addSubview:_prcieLabel];
        
        _deleteLabel = [[UILabel alloc] initWithFrame:CGRectMake(_prcieLabel.right, _prcieLabel.top + 4.5, 30, kRow)];
        _deleteLabel.textColor = COLORFROMCODE(0xA0A5A7, 1);
        _deleteLabel.font = kFont(12);
        [self addSubview:_deleteLabel];
        
        _lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 4.5, _deleteLabel.width, 1)];
        _lineLabel.hidden = YES;
        _lineLabel.backgroundColor = COLORFROMCODE(0xA0A5A7, 1);
        [_deleteLabel addSubview:_lineLabel];
        
        _timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(_deleteLabel.right, _prcieLabel.top + 2.5, kScreenWideth - _deleteLabel.right - 15, 15)];
        _timeLabel.textColor = COLORFROMCODE(0xADA5A7, 1);
        _timeLabel.font = kFont(13);
        _timeLabel.textAlignment = NSTextAlignmentRight;
        [self addSubview:_timeLabel];


        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, _prcieLabel.bottom + kRow, kScreenWideth, 53)];
        view.backgroundColor = kWhiteColor;
        [self addSubview:view];
        
        NSArray *titleArray = @[@"商品详情",@"评论(0)"];
        for (int i = 0; i < 2; i++) {
            UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
            button.frame = CGRectMake(15 + 82 * i, 11.5, 75, 30);
            [button setTitle:titleArray[i] forState:(UIControlStateNormal)];
            button.titleLabel.font = kFont(14);
            button.tag = 10 + i;
            button.layer.cornerRadius = 15;
            button.backgroundColor = kWhiteColor;
            [button setTitleColor:COLORFROMCODE(0x000000, 1) forState:(UIControlStateNormal)];

            if (i == 0) {
                [button setTitleColor:kWhiteColor forState:(UIControlStateNormal)];
                button.backgroundColor = kBasicColor;
                button.userInteractionEnabled = NO;
                UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(button.right +3.5, 20.5, 2, 12)];
                lineLabel.backgroundColor = COLORFROMCODE(0xD7D7D7, 1);
                [view addSubview:lineLabel];
            }
            [view addSubview:button];
        }
    }
    return self;
}
- (void)setDic:(NSDictionary *)dic{
    [_imageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kBaseImageUrl,[RMMFileManager retrunObjWith:dic[@"IMAGEURL"]]]] placeholderImage:[UIImage imageNamed:@"加载中@3x"]];
    _titleLabel.text = dic[@"SERVICE_NAME"];
    _prcieLabel.text = [NSString stringWithFormat:@"¥ %@",dic[@"PRICE"]];
    _deleteLabel.text = [NSString stringWithFormat:@"%@",dic[@"ORGINAL_PRICE"]];
    if (_deleteLabel.text.length) {
        _lineLabel.hidden = NO;
    } else {
        _lineLabel.hidden = YES;
    }
    _timeLabel.text = [NSString stringWithFormat:@"服务时长%@分钟",dic[@"TIME_LEN"]];
    CGFloat width = [UILabel backHeightWithString:_prcieLabel.text CGFloatCount:kMaric metho:WIDTH font:24];
    _prcieLabel.frame = CGRectMake(15, _titleLabel.bottom + 6, width, kMaric);
    CGFloat widthD = [UILabel backHeightWithString:_deleteLabel.text CGFloatCount:kRow metho:WIDTH font:12];
    _deleteLabel.frame = CGRectMake(_prcieLabel.right, _prcieLabel.top + 4.5, widthD, kRow);
    _lineLabel.frame = CGRectMake(0, 4.5, widthD, 1);

}
- (void)setTaoCanDic:(NSDictionary *)taoCanDic{
    for (int i = 0; i < 2; i++) {
        UIButton *but = [self viewWithTag:10 + i];
        but.hidden = YES;
    }
    [_imageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kBaseImageUrl,[RMMFileManager retrunObjWith:taoCanDic[@"IMAGEURL"]]]] placeholderImage:[UIImage imageNamed:@"加载中@3x"]];
    _titleLabel.text = taoCanDic[@"NAME"];
    _prcieLabel.text = [NSString stringWithFormat:@"¥ %@",taoCanDic[@"PRICE"]];
    _deleteLabel.text = [NSString stringWithFormat:@"%@",taoCanDic[@"PAR_AMT"]];
    _timeLabel.text = [NSString stringWithFormat:@"限%@使用",taoCanDic[@"REGION"]];
    if (_deleteLabel.text.length) {
        _lineLabel.hidden = NO;
    } else {
        _lineLabel.hidden = YES;
    }
    [self changedColorWith:_timeLabel];
    CGFloat width = [UILabel backHeightWithString:_prcieLabel.text CGFloatCount:kMaric metho:WIDTH font:24];
    _prcieLabel.frame = CGRectMake(15, _titleLabel.bottom + 6, width, kMaric);
    CGFloat widthD = [UILabel backHeightWithString:_deleteLabel.text CGFloatCount:kRow metho:WIDTH font:12];
    _deleteLabel.frame = CGRectMake(_prcieLabel.right, _prcieLabel.top + 4.5, widthD, kRow);
    _lineLabel.frame = CGRectMake(0, 4.5, widthD, 1);
}
- (void)changedColorWith:(UILabel *)label{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
    [attributedString addAttribute:NSForegroundColorAttributeName value:kBasicColor range:NSMakeRange(1, label.text.length - 3)];
    [label setAttributedText:attributedString];

}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
